package com.ht.power3d.vmap;

import com.ht.power3d.geop.TopoInfoReader;
import com.ht.power3d.geop.GeoGL;

import java.util.List;
import java.util.ArrayList;
import java.util.Random;

import com.ht.visiomodel.TopoInfo;

/**
 * @author SU Xinyi
 * @since 2009-5-22
 */
public class DataPointsLoaderImplWithNodes implements DataPointsLoader{
    private TopoInfo topoInfo;
    private List<DataPoint> dataPoints = new ArrayList<DataPoint>();


    public DataPointsLoaderImplWithNodes(TopoInfo topoInfo) {
        this.topoInfo = topoInfo;
        Random rand = new Random(System.currentTimeMillis());
        for(TopoInfo.Nodes.Node node : topoInfo.getNodes().getNode()){
            float x = (float) node.getGraphicalInfo().getAbscissa();
            float y = (float) (GeoGL.FRAME_HEIGHT_3D - node.getGraphicalInfo().getOrdinate());
            //float y = (float) node.getGraphicalInfo().getOrdinate();
            DataPoint newDataPoint = new DataPoint(x, y);
            float value = (float) (rand.nextDouble()*0.02+1.0-0.01);
            newDataPoint.setValue(value);
            newDataPoint.setId(node.getNodeNo().intValue());
            newDataPoint.setVoltageLevel(node.getNodeType().split("k")[0]);
            newDataPoint.setName(node.getNodeName());
            node.setNodeVoltage( value * 100 );
            dataPoints.add(newDataPoint);
        }        
    }

    public List<DataPoint> getDataPoints() {
        return dataPoints;
    }
}